import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class Dattest {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Student dattest = new Student();
        dattest.list= new ArrayList();
        Scanner sc = new Scanner(System.in);
        while (true){
            System.out.println("登录学生信息，输入n退出:");
            if (sc.next().equals("n")){
                break;
            }
            System.out.println("输入id:");
            int id =sc.nextInt();
            System.out.println("输入姓名:");
            String name = sc.next();
            System.out.println("输入性别:");
            String sex = sc.next();
            dattest.list.add(new Student(id,name,sex));
        }
        File file = new File("student.dat");
        file.createNewFile();
        FileOutputStream out = new FileOutputStream(file);
        ObjectOutputStream date = new ObjectOutputStream(out);
        date.writeObject(dattest);
        date.close();
        out.close();
        FileInputStream in=new FileInputStream(file);;
        ObjectInputStream obj=new ObjectInputStream(in);
        Student li = (Student) obj.readObject();
        obj.close();
        in.close();
        li.show();
    }
}
